package org.example.farm;

import android.app.Activity;
import android.media.MediaPlayer;
import android.media.AudioManager;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;

public class Farm extends Activity implements OnClickListener {
    /** Called when the activity is first created. */
	private MediaPlayer mp;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        setVolumeControlStream(AudioManager.STREAM_MUSIC);
        //Dog image button
        ImageView dogImage = (ImageView) findViewById(R.id.dog_image);
        dogImage.setOnClickListener(this);
        //Cat image button
        ImageView catImage = (ImageView) findViewById(R.id.cat_image);
        catImage.setOnClickListener(this);
        //Pig image button
        ImageView pigImage = (ImageView) findViewById(R.id.pig_image);
        pigImage.setOnClickListener(this);
        //Sheep image button
        ImageView sheepImage = (ImageView) findViewById(R.id.sheep_image);
        sheepImage.setOnClickListener(this);
        //Rooster image button
        ImageView roosterButton = (ImageView) findViewById(R.id.rooster_image);
        roosterButton.setOnClickListener(this);
        //Donkey image button
        ImageView donkeyButton = (ImageView) findViewById(R.id.donkey_image);
        donkeyButton.setOnClickListener(this);
        //Cow image button
        ImageView cowButton = (ImageView) findViewById(R.id.cow_image);
        cowButton.setOnClickListener(this);
        //Chicken image button
        ImageView chickenButton = (ImageView) findViewById(R.id.chicken_image);
        chickenButton.setOnClickListener(this);
      	//Chicken image button
        ImageView duckButton = (ImageView) findViewById(R.id.duck_image);
        duckButton.setOnClickListener(this);
        //Horse image button
        ImageView horseButton = (ImageView) findViewById(R.id.horse_image);
        horseButton.setOnClickListener(this);
        
        
        
    }
	public void onClick(View v) {
		// This method check which image is pressed and gives the sound resource for that image
		int resID = 0;
		switch (v.getId()) {
		case R.id.dog_image:
			resID = R.raw.dog_bark;
			break;
		case R.id.cat_image:
			resID = R.raw.cat;
			break;
		case R.id.pig_image:
			resID = R.raw.pig;
			break;
		case R.id.sheep_image:
			resID = R.raw.sheep;
			break;
		case R.id.rooster_image:
			resID = R.raw.rooster;
			break;
		case R.id.donkey_image:
			resID = R.raw.donkey;
			break;
		case R.id.cow_image:
			resID = R.raw.cow;
			break;
		case R.id.chicken_image:
			resID = R.raw.chicken;
			break;
		case R.id.duck_image:
			resID = R.raw.duck;
			break;
		case R.id.horse_image:
			resID = R.raw.horse;
			break;	

		default:
			break;
		}
		
		if(mp!=null){
			mp.release();
		}
		mp = MediaPlayer.create(this, resID);
		mp.start();
		
	}
}